package com.seal.tsms.school.controller;

import com.seal.tsms.base.controller.BaseController;
import com.seal.tsms.base.service.BaseService;
import com.seal.tsms.base.util.DateUtils;
import com.seal.tsms.school.entity.EducationInfo;
import com.seal.tsms.school.entity.StudentInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

/**
 * Created by zengzhen on 2016/1/20.
 */
@Controller
@RequestMapping("/school/studentInfo")
public class StudentInfoController extends BaseController<StudentInfo,String> {
    @Override
    @Autowired
    @Qualifier("studentInfoServiceImpl")
    public void setSelfService(BaseService<StudentInfo, String> selfService) {
        super.setSelfService(selfService);
    }

    @RequestMapping(value = "/new",method = RequestMethod.GET)
    public String create()
    {
        return "/school/studentInfo/add";
    }
    @RequestMapping(value = "/new",method = RequestMethod.POST)
    public String save(@ModelAttribute("info") StudentInfo info, @ModelAttribute("edu")EducationInfo edu, RedirectAttributes attr)
    {
        info.setCreateTime(DateUtils.getCurrentDate());
      /* EducationInfo edus=getSelfService().get(edu.getId());
        info.setEducationInfo(edu.getId());*/
        getSelfService().save(info);
        attr.addAttribute("id",info.getId());
        attr.addFlashAttribute("message","一条记录添加成功");
        return "redirect:/school/studentInfo/show.do";

    }
    @RequestMapping(value = "/show")
    public String show(@RequestParam String id, ModelMap model) {
        model.addAttribute("info", getSelfService().get(id));
        return "/school/studentInfo/show";
    }

}
